﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using DunLibrary.User;



namespace DunSilverlight.Comm
{

    /// <summary>
    /// 日志记录器
    /// owen 2011-12-10
    /// </summary>
    public class Loger
    {
        /// <summary>
        /// 写入日志
        /// </summary>
        /// <param name="opType">日志类型，</param>
        /// <param name="description"></param>
        public static void WriteLog(string opType, string description)
        {

            try
            {
                OperationLog oLog = new OperationLog();

                oLog.Oper = AppGlobal.CurrentUser;

                oLog.OpType = opType;
                oLog.Description = description;
                oLog.Organization = oLog.Oper.Organization;

                string json = Newtonsoft.Json.JsonConvert.SerializeObject(oLog);

                OperationLogService.OperationLogServiceClient ser = new OperationLogService.OperationLogServiceClient();

                ser.SaveOrUpdateCompleted += (sender, e) =>
                    {
                        ser.CloseAsync();
                    };

                ser.SaveOrUpdateAsync(json);
            }
            catch (Exception ex)
            {
                Tools.ShowMessage("写入日志失败", ex.Message, false);
            }

        }
    }
}
